﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace MvcControlToolkit
{
    public class JavaScriptElementReferenceConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            return typeof(ElementReference).IsAssignableFrom(objectType);
        }

        public override object ReadJson(JsonReader reader, Type objectType)
        {
            throw new NotImplementedException();
        }

        public override void WriteJson(JsonWriter writer, object value)
        {
            //write json value calling $get
            writer.WriteRaw(string.Concat("$get('", (value as ElementReference).ElementId, "')"));
        }
    }
}
